/**
 * @author FengLei.You
 */
function ResourceManager(opt){
	this._resources={};
	this._resourcesSize=0;
	
	this._callback=null;
	this._toLoads=[];
	this._loadIndex=0;
	
	this.context=opt.context;
	this.title=opt.title;
	this.progressTop=Me.displayCanvas.height/2-20;
	this.progressLeft=Me.displayCanvas.width/4;
	this.progressWidth=Me.displayCanvas.width/2;
	this.progressHeight=40;	
}
ResourceManager.prototype.show=function(){
	Me.trace('show called'+this._loadIndex);
	
	var context = this.context;

	context.beginPath();
    context.rect(0, 0, Me.displayCanvas.width, Me.displayCanvas.height);
    context.fillStyle = "#000000";
    context.fill();
    
    context.beginPath();
    context.rect( this.progressLeft,this.progressTop, this.progressWidth, this.progressHeight);
    context.fillStyle = "#FFFFFF";
    context.fill();
    
    var currentWidth = parseInt( this._loadIndex * this.progressWidth / this._toLoads.length );
    context.beginPath();
    context.rect(this.progressLeft,this.progressTop,  currentWidth, this.progressHeight);
    context.fillStyle = "#8ED6FF";
    context.fill();
    
    context.save();
	context.font = "30pt Calibri";
	context.fillStyle = "#0000ff";
    context.fillText(this.title, 80, 80);
    
    context.font = "20pt Calibri";
	context.fillStyle = "#ffffff";
    context.fillText('click to go', 140, 240);
    
    context.restore();
    
    
    /**/
}
ResourceManager.prototype.load=function(resources,callback){
	this._toLoads=resources;
	this._callback=callback;
	this._loadIndex=0;
	
	this._loadImage();
	this.show();
}
ResourceManager.prototype._loadImage=function(){
	var index=this._loadIndex;
	
	if(index==this._toLoads.length){
		if(this._callback){
			this._callback();
		}
		return;
	}
	
	var current = this._toLoads[index];	
	
	var _this = this;
	
	var image = new Image();
	image.onload=function(){
		_this._resources[current.name]=image;
		
		Me.trace('onload called in ');
		++_this._loadIndex;		
		_this.show();
		
		setTimeout(
			function(){
				_this._loadImage();
			}
			,
			200);
	}
	image.src=current.src;
}
ResourceManager.prototype.getImage=function(name){
	return this._resources[name];
}
